<?php
include $this->Render('header.php');
?>
<link rel="stylesheet" type="text/css" href="<?php echo BASE_STYLE;?>/css/admin.css" />
<script type="text/javascript" src="<?php echo BASE_STYLE;?>/js/dyhl.linkpage.js"></script>
<script type="text/javascript" src="<?php echo BASE_STYLE;?>/js/common.js"></script>
<style type="text/css">
    body {min-width:300px !important; overflow:scroll !important; overflow-x:hidden !important;}
    .order-item-box {
        width:100%;
        height:auto;
        overflow:hidden;
        padding-bottom:15px;
        margin-bottom:15px;
    }
</style>
<div class="tongrong-box" style="width:680px;">
    <form class="order-item-box J-ajaxForm" action="/order/trolist/option/carsave/" method="post" autocomplete="off">
        <div class="tongrong-box-main">
            <table width="70%" cellpadding="0" cellspacing="0" border="0">
                <tr>
                    <td width="20%" height="50">车型构成</td>
                    <td>
                        <input type="text" class="J-ot-car-type" value="<?php echo $this->order['car']['ot_car_pose'];?>" name="ot_car_pose" id="J-ot-car-type"/>
                    </td>
                    <td>
                        <input name="ct_code" type="hidden" id="ct_code" size="35" value="<?php echo $this->order['base']['buyer']['ct_code'];?>" />
                    </td>
                </tr>
                <tr class="J-ot-sinocap" style="display:none">
                        <td height="50">二手车选择：</td>
                        <td colspan="2">
                            <input type="text" class="J-ot-car-two1" name="et_id" id="J-ot-car-two1"/>
                        </td>
                </tr>
            </table>
        </div>
        <div style=" height:40px; overflow:hidden; margin-top:20px;">
            <input type="hidden" name="oid" value="<?php echo $this->order['base']['o_id'];?>" />
            <input type="hidden" name="o_branch_id" id="o_branch_id" value="<?php echo $this->order['base']['o_branch_id'];?>" />
            <input type="hidden" name="o_bank_id" id="o_bank_id" value="<?php echo $this->order['base']['o_bank_id'];?>" />
            <input type="submit" class="btn-submit-blue J-car_submit fn-left mr10" value="提交" />
            <a href="" class="a-btn-close J-a-et-close fn-left">关闭</a>
        </div>
</form>
</div>

<script>
    $(".J-a-et-close").on('click',function(){

        var winElement = parent.Ext.fly(window.frameElement).up('div.x-window');
        parent.Ext.getCmp(winElement.id).close();

    });

        new Ext.form.ComboBox({
            store:new Ext.data.ArrayStore({
                fields:['d_text'],
                data:[['新车'],['二手车']]
            }),
            mode:'local',
            forceSelection:true,
            triggerAction:"all",
            displayField:'d_text',
            valueField:'d_text',
            blankText : '请选择',
            allowBlank: false,
            applyTo:'J-ot-car-type',
            listeners : {
                'select':function(combo){
                    var v = combo.getValue();
                    if(v == '二手车'){
                        $(".J-ot-sinocap").show();
                        store.load();
                    }else {
                        $(".J-ot-sinocap").hide();
                    }
                }
            }
        });

    var branch_id = $("#o_branch_id").val();
    var bank_id = $("#o_bank_id").val();
    new Ext.form.ComboBox({
        store:new Ext.data.Store({
            reader: new Ext.data.JsonReader({
                fields:['text','et_id']//字段
            }),
            proxy:new Ext.data.HttpProxy({
                url:'/order/trocar/option/cardata?branch='+ branch_id +'&&bank='+ bank_id+'';
            })
        }),
        mode: 'remote',
        forceSelection:true,
        triggerAction:"all",
        displayField:'text',
        valueField:'et_id',
        hiddenName:'et_id',
        blankText : '请选择',
        allowBlank: false,
        typeAhead:true,
        width:400,
        applyTo:'J-ot-car-two1',
        listeners: {
            'beforequery':function(e){

                var combo = e.combo;
                if(!e.forceAll){
                    var input = e.query;
                    // 检索的正则
                    var regExp = new RegExp(".*" + input + ".*");
                    // 执行检索
                    combo.store.filterBy(function(record,id){
                        // 得到每个record的项目名称值
                        var text = record.get(combo.displayField);
                        return regExp.test(text);
                    });
                    combo.expand();
                    return false;
                }
            }
        }

    });


    $(".J-car_submit").on('click',function(){
        var sta = confirm('您确定要提交吗?');
        if(sta == true){
            Ext.getBody().mask("数据提交中，请稍等");
            $(".J-car_submit").dyhlForm({
                nofunction:function(){
                    $(".J-car_submit").prop('disabled',false);
                    Ext.getBody().unmask();
                },
                sucessfunction:function(data){
                    $(".J-car_submit").prop('disabled',false);
                    Ext.getBody().unmask();
                    if(data['success']){
                        Ext.Msg.alert('提示',data['msg'],function(){
                            //window.parent.App.store.reload();
                            //window.parent.trosaveItem();
                            window.parent.location.href='/order/trolist/option/troinfo?oid='+ $("[name='oid']").val()+'';
                            //window.parent.trosaveItem();
//                            window.parent.App.store.reload();
//                            var winElement = parent.Ext.fly(window.frameElement).up('div.x-window');
//                            parent.Ext.getCmp(winElement.id).close();
                        });

                    }else{
                        Ext.Msg.alert('提示',data['msg']);
                    }
                }
            });
        }else{
            return false;
        }

    });

</script>

<?php include $this->Render('footer.php'); ?>
